<template>
  <div class="collection-block">
    <div class="block-padding">
        <div class="title">
            <h3>{{title}}</h3>
            <!-- <router-link :to="`/more`">更多</router-link> -->
        </div>
        <div class="list clearfix">
            <!-- 
                不需要边距：0 2 3 5
                需要边距的：1 4

                余数：1 （1和4对3取余=1）
             -->
            <router-link 
                tag="div"
                :to="`/player/${item.id}/${item.name}/${item.song.artists[0].name}/${setUrl(item.picUrl)}`"
                class="item" 
                v-for="(item,index) in recommend" 
                :key="index"
                :class="{'clear-padding' : index%3 !== 1}"
            >
                <div class="img-warpper">
                    <img :src="item.picUrl">
                </div>
                <div class="main">{{cutString(item.name)}}</div>
                <div class="gray">{{cutString(item.song.artists[0].name)}}</div>
            </router-link>
        </div>
    </div>
  </div>
</template>

<script>
export default {
    name: "MusicRecommend",
    props:{
        recommend:{
            type:Array,
            default:function(){
                return [];
            }
        },
        title:{
            type:String,
            default:""
        }
    },
    methods:{
        //让文字显示在一行上，超出则打点
        cutString(str){
            if(str.length > 8){
                return str.substring(0, 8) + "..."
            }
            return str;
        },
        setUrl(url){
            if(url){
                return encodeURIComponent(url)
            }
        }
    }
}
</script>

<style scoped>
.collection-block {
    background-color: #f8f8f8;
    padding: 5px 0;
}

.block-padding {
    padding: 10px 17px;
    background-color: #fff;
}

.title {
    display: flex;
    margin: 14px 0 18px;
}

.title h3 {
    flex: 1 1 0%;
    display: block;
    font-weight: 700;
    font-size: 20px;
}

.list {
    width: 100%;
}

.list .item {
    float: left;
    width: 31.33%;
    padding: 0 10px;
    margin-bottom: 10px;
}

.clear-padding {
    padding: 0 !important;
}

.main {
    margin-top: 4px;
    font-size: 12px;
}

.gray {
    font-size: 12px;
    color: #999;
}

.btn-more {
    font-size: 12px;
    text-align: right;
    color: #333;
}
</style>